﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
using System.IO;
using System.IO.IsolatedStorage;
using Microsoft.Xna.Framework.Media;
using Microsoft.Devices;
using Microsoft.Phone;



namespace IDTemplate
{
    public partial class Business : PhoneApplicationPage
    {
        PhotoChooserTask photo = new PhotoChooserTask();
        CameraCaptureTask cct = new CameraCaptureTask();
        ImageBrush imgBrush = new ImageBrush();
        BitmapImage bmp = new BitmapImage();
        BitmapImage bimg = new BitmapImage();

        public Business()
        {
            InitializeComponent();
                
        }

        private void image1_Tap(object sender, GestureEventArgs e)
        {

            cct.Completed += new EventHandler<PhotoResult>(cct_Completed);
            try
            {
                cct.Show();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show("An error occurred.");
            }

        }

        void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show(e.ChosenPhoto.Length.ToString());

                //Code to display the photo on the page in an image control named myImage.
              
                bmp.SetSource(e.ChosenPhoto);
                imgBrush.ImageSource = bmp;
                ContentPanel.Background = imgBrush;
            }
        }

        void cct_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                bimg.SetSource(e.ChosenPhoto);
                image1.Source = bimg;
            }
        }

        private void textBox1_Tap(object sender, GestureEventArgs e)
        {
            textBox1.Text = "";
        }

        private void PageTitle_Tap(object sender, GestureEventArgs e)
        {
            try
            {
                 photo.Show();
                 photo.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show("An error occurred.");
            }
        }

        private void textBox2_Tap(object sender, GestureEventArgs e)
        {
            textBox2.Text = "";
        }

        private void textBox3_Tap(object sender, GestureEventArgs e)
        {
            textBox3.Text = "";
        }

        private void textBox4_Tap(object sender, GestureEventArgs e)
        {
            textBox4.Text = "";
        }
       
    }
}